package com.xrui.hbase.impl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.HTableInterface;

import java.io.IOException;

/**
 * Factory for HTableInterface that creates concrete HTable instances.
 */
public final class DefaultHTableInterfaceFactory implements HTableInterfaceFactory {
    /**
     * Singleton.
     */
    private static final HTableInterfaceFactory DEFAULT = new DefaultHTableInterfaceFactory();

    /**
     * Disallow new instances, enforce singleton.
     */
    private DefaultHTableInterfaceFactory() {
    }

    /**
     * @return the default factory singleton.
     */
    public static HTableInterfaceFactory get() {
        return DEFAULT;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public HTableInterface create(Configuration conf, String hbaseTableName) throws IOException {
        return new HTable(conf, hbaseTableName);
    }

    /**
     * {@inheritDoc}
     */
    //@Override
    public HTableInterface create(String hbaseTableName, HConnection connection) throws IOException {
        return connection.getTable(hbaseTableName);
    }
}
